import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';

export default {

  //获取法人实体关联订单list
  getLegalEntities(params) {
    return httpFetch.get(`/api/legalEntity/with/order/page`, params);
  },

  //批量开通指定法人对应服务
  batchOpenLegalEntity(serviceTypeCode, all, ids){
    return httpFetch.post(`/api/legalEntity/with/order/open/batch?serviceTypeCode=${serviceTypeCode}&all=${all}`, ids)
  },

  //批量关闭指定法人对应服务
  batchCloseLegalEntity(serviceTypeCode, all, ids) {
    return httpFetch.post(`/api/legalEntity/with/order/close/batch?serviceTypeCode=${serviceTypeCode}&all=${all}`, ids)
  },

  //获取发票袋配置列表
  getBagSettingList(page, size, params) {
    return httpFetch.post(`/api/expense/reports/bag/config/query?page=${page}&size=${size}`, params)
  },

  //保存发票袋配置
  saveBagSetting(params) {
    return httpFetch.post(`/api/expense/reports/bag/config`, params)
  },

  //删除发票袋
  deleteBag(expenseReportBagId) {
    return httpFetch.delete(`/api/expense/reports/bag/config/delete/${expenseReportBagId}`)
  },

  //校验发票袋首位是否被占用
  checkPrefix(params) {
    return httpFetch.get(`/api/expense/reports/bag/prefix/check`, params)
  },

  //取消拆单配置
  cancelSplitProfile() {
    return httpFetch.put(`/api/function/profiles/remove/splitProfile`)
  },

  //获取报销标准列表
  getReimbursementList(params) {
    return httpFetch.get(`/api/expense/standard/rule/list`, params)
  },

  //获取发票来源列表
  getInvoiceSourceList(page, size, params) {
    return httpFetch.get(`/api/receipt/source/config?page=${page}&size=${size}`, params)
  },

  //删除发票来源
  deleteInvoiceSource(id) {
    return httpFetch.delete(`/api/receipt/source/config/${id}`)
  },

  //新增／修改发票来源
  updateInvoiceSource(params) {
    return httpFetch.post(`/api/receipt/source/config`, params)
  },

  //获取报销单打印配置列表
  getExpensePrintList(page, size, params) {
    return httpFetch.post(`/api/expense/report/print/config/query?page=${page}&size=${size}`, params)
  },

  //删除报销单打印
  deleteExpensePrint(id) {
    return httpFetch.delete(`/api/expense/report/print/config/${id}`)
  },

  //新增／修改报销单打印
  updateExpensePrint(params) {
    return httpFetch.post(`/api/expense/report/print/config/save`, params)
  },

  //获取付款类型列表
  getPayTypeList(page, size, params) {
    return httpFetch.get(`/api/cash/transaction/classes/query?page=${page}&size=${size}`, params)
  },

  //新增付款类型
  newPayType(params) {
    return httpFetch.post(`/api/cash/transaction/classes`, params)
  },

  //修改付款类型
  updatePayType(params) {
    return httpFetch.put(`/api/cash/transaction/classes`, params)
  },

  //获取费用基础设置列表
  getCostBaseSettingList(page, size, params) {
    return httpFetch.post(`/api/invoice/config/all?page=${page}&size=${size}`, params)
  },

  //新增／修改费用基础设置
  updateCostBaseSetting(params) {
    return httpFetch.post(`/api/invoice/config/upsert`, params)
  },

  //删除费用基础设置
  deleteCostBaseSetting(ids) {
    return httpFetch.delete(`/api/invoice/config/delete`, ids)
  },

  //获取核销对象列表
  getWriteOffList(setOfBooksId) {
    return httpFetch.get(`/api/cash/transaction/classes/queryPaymentTransaction/${setOfBooksId}`)
  },

  // 开通免打印设置
  setFreePrintPasteConfig(params) {
    return httpFetch.post(`/api/setFreePrintPasteConfig`, params)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  // 获取免打印设置
  getFreePrintPasteConfig() {
    return httpFetch.get(`/api/getFreePrintPasteConfig`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      });
  },

  //获取抵扣设置列表
  getDeductionSetting(page, size, params) {
    return httpFetch.post(`/api/deduction/config/all?page=${page}&size=${size}`, params)
  },

  //删除抵扣设置列表
  deleteDeductionSetting(params) {
    return httpFetch.delete(`/api/deduction/config`, params)
  },

  //更新抵扣设置
  updateDeductionSetting(params) {
    return httpFetch.post(`/api/deduction/config/upsert`, params)
  },

  //获取标签详情
  getTagDetail(labelType) {
    return httpFetch.get(`/api/label`, { labelType })
  },

  //批量删除发票来源设置
  batchDeleteInvoiceSource(queryParams, ids) {
    return httpFetch.delete(`/api/receipt/source/config/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量开启或禁用发票来源设置
  batchOpenOrCloseInvoiceSource(queryParams, ids) {
    return httpFetch.post(`/api/receipt/source/config/batch/openOrClose?${parseParams(queryParams)}`, ids);
  },

  //批量删除发票管控-发票校验
  batchDeleteInvoiceCheck(queryParams, ids) {
    return httpFetch.delete(`/api/receipt/check/config/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量删除发票管控-发票生成费用
  batchDeleteInvoiceToCost(queryParams, ids) {
    return httpFetch.delete(`/api/receipt/to/invoice/config/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量删除发票管控-发票控件字段设置
  batchDeleteInvoiceControls(queryParams, ids) {
    return httpFetch.delete(`/api/receipt/display/config/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量删除价税分离规则-价税分离规则
  batchDeleteSeparationInvoice(queryParams, ids) {
    return httpFetch.delete(`/api/receipt/separation/invoice/config/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量删除价税分离规则-抵扣设置
  batchDeleteDeductionSetting(queryParams, ids) {
    return httpFetch.delete(`/api/deduction/config/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量开启或禁用价税分离规则-抵扣设置
  batchOpenOrCloseDeductionSetting(queryParams, ids) {
    return httpFetch.post(`/api/deduction/config/batch/openOrClose?${parseParams(queryParams)}`, ids);
  },

  //批量删除费用基础配置
  batchDeleteCostBaseSetting(queryParams, ids) {
    return httpFetch.delete(`/api/invoice/config/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量开启或禁用费用基础配置
  batchOpenOrCloseCostBaseSetting(queryParams, ids) {
    return httpFetch.post(`/api/invoice/config/batch/openOrClose?${parseParams(queryParams)}`, ids);
  },

  //批量删除报销设置-报销单提交管控
  batchDeleteExpenseControl(queryParams, ids) {
    return httpFetch.delete(`/config/api/config/rule/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量删除报销设置-报销单打印设置
  batchDeleteExpensePrint(queryParams, ids) {
    return httpFetch.delete(`/api/expense/report/print/config/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量开启或禁用报销设置-报销单打印设置
  batchOpenOrCloseExpensePrint(queryParams, ids) {
    return httpFetch.post(`/api/expense/report/print/config/batch/openOrClose?${parseParams(queryParams)}`, ids);
  },

  //批量开启或禁用报销设置-付款类型
  batchOpenOrCloseExpensePayType(queryParams, ids) {
    return httpFetch.post(`/api/cash/transaction/classes/batch/openOrClose?${parseParams(queryParams)}`, ids);
  },

  //批量删除发票袋设置
  batchDeleteInvoiceBag(queryParams, ids) {
    return httpFetch.delete(`/api/expense/reports/bag/config/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量开启或禁用发票袋设置
  batchOpenOrCloseInvoiceBag(queryParams, ids) {
    return httpFetch.post(`/api/expense/reports/bag/config/batch/openOrClose?${parseParams(queryParams)}`, ids);
  },

  //批量删除报销标准
  batchDeleteReimbursementStandard(queryParams, ids) {
    return httpFetch.delete(`/api/expense/standard/rule/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量开启或禁用报销标准`
  batchOpenOrCloseReimbursementStandard(queryParams, ids) {
    return httpFetch.post(`/api/expense/standard/rule/batch/openOrClose?${parseParams(queryParams)}`, ids);
  },

  //批量删除报销单提交管控
  batchDeleteSubmissionControl(queryParams, ids) {
    return httpFetch.delete(`/api/expense/standard/rule/batch/delete?${parseParams(queryParams)}`, ids);
  },

  //批量开启或禁用报销单提交管控
  batchOpenOrCloseSubmissionControl(queryParams, ids) {
    return httpFetch.post(`/api/expense/standard/rule/batch/openOrClose?${parseParams(queryParams)}`, ids);
  },
};

const parseParams = queryParams => {
  return Object.keys(queryParams).map(i => `${i}=${queryParams[i] === false ? 'false' : (queryParams[i] || '')}`).join('&')
};
